package com.wnhz.work.jy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wnhz.work.jy.R;
import com.wnhz.work.jy.bean.ChooseAddressBean;

import java.util.List;

/**
 * Created by Administrator on 2016/10/10 0010.
 */
public class MyAddressAdapter extends BaseAdapter {
    private Context context;
    private List<ChooseAddressBean> chooseLise;
    private View.OnClickListener listener;

    public MyAddressAdapter(Context context, List<ChooseAddressBean> chooseLise, View.OnClickListener listener) {
        this.context = context;
        this.chooseLise = chooseLise;
        this.listener = listener;
    }

    @Override
    public int getCount() {
        return chooseLise.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyAddressViewHolder viewHolder = new MyAddressViewHolder();
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.my_address_item, null);
            viewHolder.rl_choose_true = (RelativeLayout) convertView.findViewById(R.id.rl_choose_true);
            viewHolder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);//姓名
            viewHolder.tv_phone = (TextView) convertView.findViewById(R.id.tv_phone);//电话
            viewHolder.tv_address = (TextView) convertView.findViewById(R.id.tv_address);//地址
            viewHolder.tv_compile = (TextView) convertView.findViewById(R.id.tv_compile);//编辑

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (MyAddressViewHolder) convertView.getTag();
        }

        viewHolder.tv_name.setText(chooseLise.get(position).getName());
        viewHolder.tv_phone.setText(chooseLise.get(position).getPhone());

        String getCity = chooseLise.get(position).getCity();
        String getArea = chooseLise.get(position).getArea();
        String getDoorplate = chooseLise.get(position).getDoorplate();

        String getsheng = chooseLise.get(position).getProvince();
        String getshi = chooseLise.get(position).getCitys();
        String getqu = chooseLise.get(position).getAreas();
        String addrs = chooseLise.get(position).getAddress();

        viewHolder.tv_address.setText(getsheng + getshi + getqu + addrs);
        System.out.println(getsheng + getshi + getqu + addrs + "我的地址");

        viewHolder.tv_compile.setOnClickListener(listener);
        viewHolder.tv_compile.setTag(position);

        return convertView;
    }

    class MyAddressViewHolder {
        RelativeLayout rl_choose_true;
        TextView tv_name;
        TextView tv_phone;
        TextView tv_address;
        TextView tv_compile;

    }
}
